package com.dingreading.cloud.subject.service.impl;

import com.dingreading.cloud.subject.entity.StaffRoles;
import com.dingreading.cloud.subject.entity.table.StaffRolesTableDef;
import com.dingreading.cloud.subject.mapper.StaffRolesMapper;
import com.dingreading.cloud.subject.service.StaffRolesService;
import com.mybatisflex.core.query.QueryCondition;
import org.springframework.stereotype.Service;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2025-07-23
 */
@Service
public class StaffRolesServiceImpl extends BaseServiceImpl<StaffRolesMapper, StaffRoles, StaffRolesTableDef> implements StaffRolesService {

    @Override
    protected StaffRolesTableDef getTable() {
        return StaffRolesTableDef.staffRoles;
    }

    @Override
    public boolean existStoreUid(String storeUid, String staffUid) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.staffUid.eq(staffUid))
                .and(table.storeUid.eq(storeUid))
                .and(table.enabled.eq(1));
        return exists(condition);
    }

    @Override
    public StaffRoles getStoreUidAndStaffUid(String storeUid, String staffUid) {
        QueryCondition condition = QueryCondition.createEmpty()
                .and(table.staffUid.eq(staffUid))
                .and(table.storeUid.eq(storeUid))
                .and(table.enabled.eq(1));

        return getMapper().selectOneByCondition(condition);
    }
}
